package org.smr.ministore.micro;

import java.util.List;

import org.blade.dao.base.BaseMapper;
import org.blade.utils.IdGenUtils;
import org.smr.ministore.dao.BrandMapper;
import org.smr.ministore.entities.Brand;
import org.smr.ministore.entities.vo.Assign2OrganVO;
import org.smr.ministore.entities.vo.Assign2OrgansVO;
import org.smr.ministore.service.BrandService;
import org.blade.service.base.AbstractService;

import org.blade.utils.Pager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


@RestController
public class BrandMicroService extends AbstractService<Long, Brand> implements BrandService {

	@Autowired
	private BrandMapper mapper;

	@Resource(name="brandServiceFacade")
	private BrandService brandService;

	@Autowired
    public BrandMicroService(BrandMapper mapper) {
        super(mapper);
    }

    @ResponseBody
	@RequestMapping(method = RequestMethod.POST, value = "/Brand/batchSave")
	public int batchSave(@RequestBody List<Brand> entities) {
        this.batchSaveAttatch(entities);
    	return mapper.batchInsert(entities);
    }

    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/Brand/batchModify")
    public int batchModify(List<Brand> entities) {
        this.batchModifyAttatch(entities);
        return mapper.batchUpdate(entities);
    }


    @ResponseBody
    @RequestMapping(method = RequestMethod.PUT, value = "/Brand/save")
    public int save(@RequestBody Brand entity) {
    	return brandService.save(entity);
    }

    @ResponseBody
    @RequestMapping(method = RequestMethod.PATCH, value = "/Brand/updateById")
    public int updateById(@RequestBody Brand id) {
   	 	return brandService.updateById(id);
    }

    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/Brand/queryById/{id}")
    public Brand queryById( @PathVariable("id")Long id ) {
    	return  brandService.queryById(id);
    }

    @ResponseBody
    @RequestMapping(method = RequestMethod.DELETE, value = "/Brand/deleteById/{id}")
    public int deleteById( @PathVariable("id")Long id ) {
        return brandService.deleteById(id);
    }

    @ResponseBody
    @RequestMapping( method = RequestMethod.POST, value = "/Brand/paginate/{pageSize}/{pageNum}")
    public Pager<Brand> paginate(@RequestBody Brand entity, @PathVariable("pageSize")Long pageSize,  @PathVariable("pageNum")Long pageNum ) {
        return brandService.paginate(entity, pageSize, pageNum);
    }


    @Override
    @ResponseBody
    @RequestMapping( method = RequestMethod.DELETE, value = "/BrandOrgan/remove/{id}")
    public int deleteByIdLogical(@PathVariable("id")Long id) {
        return this.brandService.deleteByIdLogical(id);
    }

    @Override
    @ResponseBody
    @RequestMapping( method = RequestMethod.POST, value = "/BrandOrgan/assignToOrgans")
    public int assignToOrgans(@RequestBody Assign2OrgansVO assignee) {
        return brandService.assignToOrgans(assignee);
    }

    @Override
    @ResponseBody
    @RequestMapping( method = RequestMethod.POST, value = "/BrandOrgan/assign")
    public int assign(@RequestBody Assign2OrganVO sssign2Organ) {
        return brandService.assign(sssign2Organ);
    }

    @Override
    public Long getId() {
        return IdGenUtils.getNextLongId();
    }
}
